package com.training.android.tictactoe;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class TicTacToeActivity extends Activity {
	/** Called when the activity is first created. */

	Button multiPlayerButton,singlePlayerButton, rulesButton, exitButton;
	Intent activityIntent;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_start);

		initComponent();
	}

	private void initComponent() {
		singlePlayerButton = (Button) findViewById(R.id.singlePlayerButton);
		multiPlayerButton = (Button) findViewById(R.id.multiPlayerButton);
		rulesButton = (Button) findViewById(R.id.rulesButton);
		exitButton = (Button) findViewById(R.id.exitButton);
		singlePlayerButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				clickHandler(1);
			}
		});
		multiPlayerButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				clickHandler(2);
			}
		});
		rulesButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				clickHandler(3);
			}
		});
		exitButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				clickHandler(4);
			}
		});
	}

	public void clickHandler(int operation) {
		switch (operation) {
		case 1:
			activityIntent = new Intent(TicTacToeActivity.this, GameActivity.class);
			activityIntent.putExtra("gameMode", 1);
			startActivity(activityIntent);
			break;
		case 2:
			activityIntent = new Intent(TicTacToeActivity.this, GameActivity.class);
			activityIntent.putExtra("gameMode", 2);
			startActivity(activityIntent);
			break;
		case 3:
			activityIntent = new Intent(TicTacToeActivity.this, RulesActivity.class);
	    	startActivity(activityIntent);
			break;
		case 4:
			finish();
			break;
		default:
			finish();
			break;
		}
	}
}